package com.dongdongshop.controller;


import com.dongdongshop.data.Result;
import com.dongdongshop.domain.req.TbGoodsReq;
import com.dongdongshop.domain.res.TbGoodsRes;
import com.dongdongshop.service.TbGoodsService;
import com.dongdongshop.config.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private TbGoodsService tbGoodsService;

    @RequestMapping("/insert")
    public Result insert(@RequestBody TbGoodsReq tbGoodsReq) {
        tbGoodsReq.setSellerId((String) ThreadLocalUtil.getThreadLocal());
        tbGoodsReq.setAuditStatus("0");
        tbGoodsReq.setIsMarketable("0");
        tbGoodsService.insert(tbGoodsReq);
        return Result.success();
    }

    @GetMapping("queryAll")
    public Result<List<TbGoodsRes>> queryAll() {
        List<TbGoodsRes> tbGoodsRes=tbGoodsService.queryAll();
        return Result.success(tbGoodsRes);
    }

    @GetMapping("queryBySellerId")
    public Result<List<TbGoodsRes>> queryBySellerId() {
        List<TbGoodsRes> tbGoodsRes=tbGoodsService.queryBySellerId((String) ThreadLocalUtil.getThreadLocal());
        return Result.success(tbGoodsRes);
    }

    @PostMapping("updateAuditStatus")
    public Result updateAuditStatus(@RequestBody TbGoodsReq tbGoodsReq) {
        tbGoodsService.updateAuditStatus(tbGoodsReq);
        return Result.success();
    }
}
